home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / SinkShips 2.2.2 / SinkShips.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-15  |  4.8 KB  |  182 lines  |  [TEXT/CWIE]

  1. #include    <stdlib.h>
  2. #include    <Sound.h>
  3. #include    <Quickdraw.h>
  4.  
  5. #define MAXLONG                        32768
  6.  
  7. #define kGridSize                    10
  8.  
  9. #define kBaseResID                    128
  10. #define kYouWindowID                kBaseResID
  11. #define kEnemyWindowID                kBaseResID + 1
  12. #define kTextWindowID                kBaseResID + 2
  13. #define kMoveToFront                (WindowPtr)-1L
  14.  
  15. #define kRandomUpperLimit            32768
  16. #define kRandomRange                kGridSize
  17.  
  18. #define kBombDropSnd                5000
  19. #define kExplosionSnd                5001
  20. #define kSplashSnd                    5002
  21. #define kYouSankSnd                    5003
  22. #define kYouWinSnd                    5004
  23. #define kYouLoseSnd                    5005
  24.  
  25. #define kNoSound                    0
  26. #define kSound                        1
  27.  
  28. #define wYou                        kBaseResID
  29. #define wComputer                    kBaseResID+1
  30. #define wText                        kBaseResID+2
  31.  
  32. #define kPixelSize                    20
  33. #define kNullDotID                    144
  34. #define kBWHitDotID                    143
  35. #define kHitDotID                    145
  36. #define kMissDotID                    146
  37. #define kMinSpacedShots                35
  38.  
  39. #define kHorizDestroyerID            200
  40. #define kVertDestroyerID            201
  41. #define kHorizCruiserID                202
  42. #define kVertCruiserID                203
  43. #define kHorizSubID                    204
  44. #define kVertSubID                    205
  45. #define kHorizSinkShipID            206
  46. #define kVertSinkShipID                207
  47. #define kHorizCarrierID                208
  48. #define kVertCarrierID                209
  49.  
  50. #define kCarrierMin                    2
  51. #define kCarrierMax                    2
  52. #define kSinkShipMin                1
  53. #define kSinkShipMax                2
  54. #define kCruiserMin                    1
  55. #define kCruiserMax                    1
  56. #define kSubMin                        1
  57. #define kSubMax                        1
  58. #define kDestroyerMin                0
  59. #define kDestroyerMax                1
  60.  
  61. #define kCarrierSize                5
  62. #define kSinkShipSize                4
  63. #define kCruiserSize                3
  64. #define kSubSize                    3
  65. #define kDestroyerSize                2
  66.  
  67. #define kNumShips                    5
  68. #define kNoShip                        -1
  69. #define kSinkShip                    0
  70. #define kCarrier                    1
  71. #define kCruiser                    2
  72. #define kSub                        3
  73. #define kDestroyer                    4
  74.  
  75. #define mApple                        kBaseResID
  76. #define iAbout                        1
  77.  
  78. #define mFile                        kBaseResID + 1
  79. #define iNew                        1
  80. #define iQuit                        2
  81.  
  82. #define  mOptions                    kBaseResID + 3
  83. #define iSound                        1
  84.  
  85. #define kAddCheckMark                TRUE
  86. #define kRemoveCheckMark            FALSE
  87.  
  88. #define iPlayAgainCheckBox            1
  89. #define iQuitCheckBox                2
  90.  
  91. #define kExtraPopupPixels            25
  92.     
  93. #define kSpaceBarKey                49
  94.  
  95. #define    kVersionNumberStr            "\pv2.1"
  96.  
  97. #define kCongratulationsStr            "\pCongratulations!"
  98. #define kYouWinStr                    "\pYou Win!"
  99. #define kSorryStr                    "\pSorry."
  100. #define kYouLoseStr                    "\pYou Lose."
  101. #define kRotateStr                    "\pPress any key to rotate the ship."
  102. #define kPlaceStr                    "\pPress the mouse button to place the ship."
  103.  
  104. /***********/
  105. /* Structs */
  106. /***********/
  107.  
  108. typedef enum {
  109.     right, left, up, down
  110. } Direction;
  111.  
  112. typedef enum {
  113.     carrier = 1, battleship, cruiser, sub, destroyer
  114. } ShipsEnum;
  115.  
  116. typedef enum {
  117.     noTry = 144, hit, miss
  118. } cond;
  119.  
  120. typedef struct {
  121.     int        shipType;
  122.     int        shipResID;
  123.     cond    hitOrMiss;
  124. } Grid;
  125.  
  126.  
  127. /***********/
  128. /* Globals */
  129. /***********/
  130.  
  131. int            youCount = 0, enemyCount = 0, shotCount = 0;
  132. int            hitShips[kNumShips];
  133. Boolean        gDone, gYouHasGone = FALSE, gHasSound = FALSE, useColor;
  134. Grid        enemy [kGridSize] [kGridSize], you [kGridSize] [kGridSize];
  135. WindowPtr    enemyWindow, youWindow;
  136.  
  137.  
  138. /*************/
  139. /* Functions */
  140. /*************/
  141.  
  142. void    ToolBoxInit ( void );
  143. void    WindowInit ( void );
  144. void    MenuBarInit ( void );
  145. void    EventLoop ( void );
  146. void    DoEvent ( EventRecord *eventPtr );
  147. void    HandleMouseDown ( EventRecord *eventPtr );
  148. void    DoUpdate ( EventRecord *eventPtr );
  149. void    HandleMenuChoice ( long menuChoice );
  150. void    HandleAppleChoice ( short item );
  151. void    HandleFileChoice ( short item );
  152. void    NewGame ( void );
  153. void    DrawDots ( Grid theGrid[][kGridSize] );
  154. void    GridInit ( Grid aGrid[][kGridSize] );
  155. void    PlaceEnemyShips ( void );
  156. void    DrawShipPart ( int resID, Rect pictureRect );
  157. int        Randomize ( void );
  158. void    PlaceAnEnemyShip ( int shipSize, int min, int max, int c );
  159. Boolean    FitsHoriz ( Grid theGrid[][kGridSize], int x, int y, int shipSize );
  160. Boolean    FitsVert ( Grid theGrid[][kGridSize], int x, int y, int shipSize );
  161. void    CheckPoint ( Point mouseLocal );
  162. void    DrawOneDot ( int dotID, Rect *dotRect );
  163. void    PtToDotRect ( Point aPoint, Rect *aRect );
  164. void    PtToRect ( Point aPoint, Rect *aRect );
  165. void    EraseShipPart ( Rect pictureRect );
  166. void    PlaceAShip ( int theMin, int theMax, int theHorizID, int theShip );
  167. void    PtToShipRect ( Point aPoint, Rect *aRect, Boolean horiz, int min, int max );
  168. Boolean    Inbounds ( Point *tempPoint, Boolean horiz, int min, int max );
  169. void    DrawHorizDots ( Point aPoint, Point tempPoint, Rect *theRect, int min, int max );
  170. void    DrawVertDots ( Point aPoint, Point tempPoint, Rect *theRect, int min, int max );
  171. void    SetShipToGrid ( Grid theGrid[][kGridSize], Point tempPoint, 
  172.                             Boolean horiz, int min, int max, int c );
  173. Boolean    ItFits ( Boolean horiz, Point thePoint, int theMin, int theMax );
  174. cond    PlaceTheShot ( Point thePoint );
  175. void    PickEnemyShot ( void );
  176. void    HandleOptionsChoice ( short item );
  177. void    HandleSound ( void );
  178. Boolean    IsColour( void );
  179. Boolean    IsBadRandom ( Point thePoint, Boolean canCheck );
  180. void    InitShips ( void );
  181. int        CheckIfSink ( int theShip, Boolean play );
  182.